
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            *{
                margin:0px;
                padding:0px;
                list-style: none;
            }
            div{
                width: 520px;
                height: 280px;
                margin:100px auto;
                position: relative;
               
                overflow: hidden;
            }
            ul{
                width:9999px ;
                transform: translateX(0px);
            }
            ul li{
                float: left;
            }
            ol{
                position: absolute;
                bottom:10px;
                left: 50%;
               
                transform: translateX(-50%);
            }
            ol li{
                width: 10px;
                height: 10px;
                border-radius: 50%;
                background:white;
                float: left;
                margin:0px 4px;
                cursor: pointer;
            }
            span{
                position: absolute;
                top:50%;
                transform: translateY(-50%);
               
                cursor: pointer;
            }
            span:nth-of-type(1){
                left:10px;
            }
            span:nth-of-type(2){
                right:10px;
            }
          


            .current{
                background: #f60;
            }
        </style>
    </head>
    <body>
        <div id="bigbox">
           
            <ul id="main">
                <li>
                    <img src="images/pic1.jpg" alt="">
                </li>
                <li>
                    <img src="images/pic2.jpg" alt="">
                </li>
                <li>
                    <img src="images/pic3.jpg" alt="">
                </li>
                <li>
                    <img src="images/pic4.jpg" alt="">
                </li>

                <li>

                    <img src="images/pic5.jpg" alt="">
                </li>
            </ul>
            
            <ol id="list">
                <li class="current"></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ol>
            
            <span id="left">《
                
            </span>
            <span id="right">》</span>
            <script>
                
                var main=document.getElementById('main');
                var bigbox=document.getElementById('bigbox');
                var left=document.getElementById('left');
                var right=document.getElementById('right');
               
                var list=document.getElementById('list').children;
                
                var num=0;
                var timer;
               
                function fn(){
                  
                    timer=setInterval(function(){
                        num++;
                        if(num>3){
                            num=0;
                        }
                       
                        main.style.transform='translate('+(-520*num)+'px)';
                    
                        for(var i=0;i<list.length;i++){
                            list[i].className='';
                        }
                        
                        list[num].className='current'

                    },1000)
                }
                fn()

               
                bigbox.onmouseenter=function(){
                  
                    clearInterval(timer)
                }
                
                bigbox.onmouseleave=function(){
                    fn()
                }

               
                for(var n=0;n<list.length;n++){
                  
                    list[n].zsh=n;
                    list[n].onclick=function(){
                      
                        for(var i=0;i<list.length;i++){
                            list[i].className='';

                        }
                        this.className='current'
                    
                        num=this.zsh
                        main.style.transform='translate('+(-520*num)+'px)';
                    }
                }
       
                right.onclick=function(){
                        num++;
                        if(num>3){
                            num=0;
                        }
                        
                        main.style.transform='translate('+(-520*num)+'px)';
              
                        for(var i=0;i<list.length;i++){
                            list[i].className='';
                        }
              
                        list[num].className='current'                   
                }
 
                left.onclick=function(){
                        num--;
                        if(num<0){
                            num=3;
                        }
                      
                        main.style.transform='translate('+(-520*num)+'px)';
                
                        for(var i=0;i<list.length;i++){
                            list[i].className='';
                        }
                       
                        list[num].className='current'
                   
                }
            </script>
        </div>
    </body>
</html>
